package com.usian.admin.controller;

import com.usian.admin.AdChannelControllerApi;
import com.usian.admin.service.AdChannelService;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理模块",tags = "channel",description = "频道管理api文档")
public class AdChannelController  implements AdChannelControllerApi {

    @Autowired
    private AdChannelService adChannelService;


    /**
     * 频道列表查询
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @Override
    @ApiOperation(value = "频道列表查询",notes = "分页频道列表查询方法")
    @ApiImplicitParam(name = "dto",type = "ChannelDto",value = "查询条件中包含频道名称")
    public ResponseResult findPage(@RequestBody ChannelDto dto) {
        ResponseResult page = adChannelService.findPage(dto);
        return page;
    }

    /**
     * 频道保存
     *
     * @param adChannel
     * @return
     */
    @PostMapping("/save")
    @Override
    public ResponseResult insertChannel(@RequestBody AdChannel adChannel) {
        return adChannelService.insertChannel(adChannel);
    }

    /**
     *  修改频道
     *
     * @param adChannel
     * @return
     */
    @PostMapping("/update")
    @Override
    public ResponseResult updateChannel(@RequestBody AdChannel adChannel) {
        return adChannelService.updateChannel(adChannel);
    }

    /**
     * 删除频道
     *
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    @Override
    public ResponseResult removeById(@PathVariable Integer id) {
        return adChannelService.deleteById(id);
    }

    /**
     * 提供wemedia微服务列表查询的频道列表数据
     *
     * @return
     */
    @Override
    @GetMapping("/channels")
    public ResponseResult channels() {
        List<AdChannel> adChannelList = adChannelService.list();
        return  ResponseResult.okResult(adChannelList);
    }
}
